<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Model</title>
    <script src="jquery/jquery-1.11.2.js"></script>
    <script src="underScore/underscore.js"></script>
    <script src="backbone-min.js"></script>
</head>
<body>

<script>
    (function($){
        var Man = Backbone.Model.extend({
            url:'index.php',
            initialize:function()
            {
                alert('hi backbone Model initialize');
                this.bind("change:name",function(){
                    var name = this.get('name');
                    alert('you change name: '+name);
                });
                this.bind('invalid',function(model,error){
                    alert(error);
                })
            },
            defaults:
            {
                name:'backbone',
                age:'12'
            },
            validate:function(attributes)
            {
                if(attributes.name == 'javascript')
                {
                    return 'name 错误';
                }
            },
            aboutMe:function()
            {
                return 'My name ' + this.get('name');
            }
        });
        var man = new Man;
        man.set({'sex':'male'});
//        alert(man.get('sex'));
//        alert(man.aboutMe());
        man.save();
        var man1 = new Man;
        man1.fetch({
            url:'index.php',
            success:function(model,response)
            {
                alert('success');
                alert(model.get('name'));
            },error:function()
            {
                alert('error');
            }
        });
    })(jQuery);
</script>
</body>
</html>